
package com.wwy.monitor.util;

import java.util.Collection;
import java.util.List;

import com.google.common.collect.Lists;
import org.dozer.DozerBeanMapper;

/**
 * @author xinqiang.sxq    xinqiang.sxq@autonavi.com
 * @ClassName: BeanMapper
 * @Description: ç®åå°è£Dozer, å®ç°æ·±åº¦è½¬æ¢Bean<->BeançMapper.å®ç°:
 * <p>
 * 1. ææMapperçåä¾.
 * 2. è¿åå¼ç±»åè½¬æ¢.
 * 3. æ¹éè½¬æ¢Collectionä¸­çææå¯¹è±¡.
 * 4. åºååå»ºæ°çBå¯¹è±¡ä¸å°å¯¹è±¡Aå¼å¤å¶å°å·²å­å¨çBå¯¹è±¡ä¸¤ç§å½æ°.
 * @date 2016å¹´4æ21æ¥ ä¸å6:26:53
 */
public class BeanMapper {
    /**
     * ææDozeråä¾, é¿åéå¤åå»ºDozerMapperæ¶èèµæº.
     */
    private static DozerBeanMapper dozer = new DozerBeanMapper();

    /**
     * åºäºDozerè½¬æ¢å¯¹è±¡çç±»å.
     */
    public static <T> T map(Object source, Class<T> destinationClass) {
        return dozer.map(source, destinationClass);
    }

    /**
     * åºäºDozerè½¬æ¢Collectionä¸­å¯¹è±¡çç±»å.
     */
    @SuppressWarnings("rawtypes")
    public static <T> List<T> mapList(Collection sourceList, Class<T> destinationClass) {
        List<T> destinationList = Lists.newArrayList();
        for (Object sourceObject : sourceList) {
            T destinationObject = dozer.map(sourceObject, destinationClass);
            destinationList.add(destinationObject);
        }
        return destinationList;
    }

    /**
     * åºäºDozerå°å¯¹è±¡Açå¼æ·è´å°å¯¹è±¡Bä¸­.
     */
    public static void copy(Object source, Object destinationObject) {
        dozer.map(source, destinationObject);
    }
}